import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import dayjs, { Dayjs } from 'dayjs';
// import { rules } from '/@/utils/helper/validator';
import { render } from '/@/utils/common/renderUtils';
import { useI18n } from '/@/hooks/web/useI18n';
const { t } = useI18n('asset.assetBorrowing.fields');
const { t: common } = useI18n('common');
const assetBorrowingFields = {
  user: t('user'),
  department: t('department'),
  position: t('position'),
  description: t('description'),
  documentFileString: t('documentFileString'),
  returnTime: t('returnTime'),
  status: t('status'),
  number: t('number'),
  createTime: t('createTime'),
  operater: t('operater'),
};
//列表数据
export const columns: BasicColumn[] = [
  {
    title: assetBorrowingFields.number,
    align: 'center',
    dataIndex: 'id',
  },
  {
    title: assetBorrowingFields.user,
    align: 'center',
    dataIndex: 'user_dictText',
  },
  // {
  //   title: assetBorrowingFields.department,
  //   align: 'center',
  //   dataIndex: 'department_dictText',
  // },
  // {
  //   title: assetBorrowingFields.position,
  //   align: 'center',
  //   dataIndex: 'position_dictText',
  // },
  {
    title: assetBorrowingFields.returnTime,
    align: 'center',
    dataIndex: 'returnTime',
    customRender: ({ text }) => {
      return !text ? '' : text.length > 10 ? text.substr(0, 10) : text;
    },
  },
  {
    title: assetBorrowingFields.description,
    align: 'center',
    dataIndex: 'description',
  },
  {
    title: assetBorrowingFields.status,
    align: 'center',
    dataIndex: 'status',
    customRender: ({ text }) => {
      return render.renderDict(text, 'documentStatus', true, { '2': 'blue', '3': 'green', '4': 'red' });
    },
  },
];

//查询数据
export const searchFormSchema: FormSchema[] = [
  {
    label: assetBorrowingFields.user,
    field: 'user',
    component: 'JSelectUserByDept',
    componentProps: {
      showButton: false,
    },
  },
  {
    label: assetBorrowingFields.status,
    field: 'status',
    component: 'JSelectMultiple',
    defaultValue: '1,2',
    componentProps: {
      dictCode: 'documentStatus',
      showChooseOption: false,
      multiple: true,
    },
  },

  {
    label: assetBorrowingFields.createTime,
    field: 'createTime',
    component: 'RangePicker',
  },
  {
    label: assetBorrowingFields.operater,
    field: 'updateBy',
    component: 'JSelectUserByDept',
    componentProps: {
      showButton: false,
    },
  },
  {
    label: assetBorrowingFields.number,
    field: 'id',
    component: 'JInput',
    componentProps: {
      type: 'like',
    },
  },
];

//表单数据
export const formSchema: FormSchema[] = [
  {
    label: assetBorrowingFields.user,
    field: 'user',
    component: 'JSelectUserByDept',
    componentProps: {
      labelKey: 'realname',

      maxSelectCount: 1,
    },
    dynamicRules: () => {
      return [{ required: true, message: `${common('chooseText')}${assetBorrowingFields.user}!` }];
    },
  },
  // {
  //   label: assetBorrowingFields.department,
  //   field: 'department',
  //   component: 'JSelectDept',
  //   dynamicRules: () => {
  //     return [{ required: true, message: `${common('chooseText')}${assetBorrowingFields.department}!` }];
  //   },
  // },
  // {
  //   label: assetBorrowingFields.position,
  //   field: 'position',
  //   component: 'JTreeSelect',
  //   componentProps: {
  //     dict: 'asset_position,position_name,id',
  //     pidField: 'pid',
  //     pidValue: '0',
  //     hasChildField: 'has_child',
  //   },
  //   dynamicRules: () => {
  //     return [{ required: true, message: `${common('chooseText')}${assetBorrowingFields.position}!` }];
  //   },
  // },
  {
    label: assetBorrowingFields.returnTime,
    field: 'returnTime',
    component: 'DatePicker',
    componentProps: {
      disabledDate: (current: Dayjs) => {
        return (current && current < dayjs().endOf('day')) || current > dayjs().add(3, 'month');
      },
    },
    dynamicRules: () => {
      return [{ required: true, message: `${common('chooseText')}${assetBorrowingFields.returnTime}!` }];
    },
  },
  {
    label: assetBorrowingFields.description,
    field: 'description',
    component: 'Input',
  },
  {
    label: assetBorrowingFields.documentFileString,
    field: 'documentFileString',
    component: 'JUpload',
    componentProps: {},
  },
  // TODO 主键隐藏字段，目前写死为ID
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false,
  },
];
